home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / boxingbagChar.lua < prev    next >
Text File  |  2004-01-29  |  3KB  |  138 lines

  1. -- boxing character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local bag = getStateObjectFromID(msg.sender);
  6.         storeStateObject("bag", bag);
  7.         
  8.         if (bag) then
  9.             -- bag does exist
  10.             local actionPointName = retrieveData("actionPointName");
  11.             local actionPoint = getParent().getFreeActionPoint(bag, actionPointName);
  12.             
  13.             if (not actionPoint) then
  14.                 -- action points is locked
  15.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  16.                 sendMsg("emoThink", getParent().walkSO);
  17.                 exitStateMachine();
  18.             else
  19.                 getParent().lockActionPoint(bag, actionPointName);
  20.             end
  21.         else
  22.             -- sink does not exist anymore
  23.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  24.             sendMsg("emoThink", getParent().walkSO);
  25.             exitStateMachine();
  26.         end
  27.         
  28.         freeHands(getParent());
  29.                 
  30.     end )
  31.     
  32.     onExit(function(msg)
  33. --        local bag = retrieveStateObject("bag");
  34. --        if (bag) then
  35. --            getParent().stopAllActivities(bag);
  36. --            getParent().unlockActionPoints(bag);
  37. --            removeStateObject("bag");
  38. --        end
  39.         
  40.         unlockAll("bag");
  41.     end )
  42.     
  43.     
  44.     
  45.     state("boxStart")
  46.     
  47.         onEnter(function(msg)
  48.             startAnimation("boxingStart");
  49.         end )
  50.         
  51.         onMsg("end", function(msg)
  52.             
  53.             if testCancel() then
  54.                 setState("boxStop")
  55.             else
  56.                 setState("box")
  57.             end
  58.         end )    
  59.     
  60.     
  61.     state("box")
  62.     
  63.         onEnter(function(msg)
  64.             
  65.             local bag = retrieveStateObject("bag");
  66.             local box = getParent().startActivity("box", bag);
  67.             length, scale = getActivityLength(box);
  68.             storeData("scale", scale);
  69.  
  70.             sendDelayedMsgThis("stopBoxing", length);
  71.             sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  72.             
  73.             sendMsgThis("startLoop");
  74.             
  75.             local others = getOtherUsers(getParent(), bag, "box");
  76.             if (not others[1]) then
  77.                 bag.loopSound("boxingBag");
  78.             end;
  79.             
  80.         end )
  81.         
  82.         onExit(function(msg)
  83.             local bag = retrieveStateObject("bag");
  84.             bag.stopSound("boxingBag");
  85.         end )
  86.             
  87.         onMsg("startLoop", function(msg)
  88.             startAnimation("boxing", false, retrieveData("scale", 1.0));
  89.             sendDelayedMsgThis("punch", 2800);
  90.             sendDelayedMsgThis("punch", 3100);
  91.             sendDelayedMsgThis("punch", 3400);
  92.             sendDelayedMsgThis("punch", 4850);
  93.             sendDelayedMsgThis("punch", 5450);
  94.             sendDelayedMsgThis("punch", 6200);
  95.             sendDelayedMsgThis("punch", 6770);
  96.             sendDelayedMsgThis("punch", 7150);
  97.             sendDelayedMsgThis("punch", 7860);
  98.         end )
  99.             
  100.         onMsg("punch", function(msg)
  101.             getParent().playSound("punch" .. random(1,2));
  102.         end )    
  103.         
  104.         onMsg("stopBoxing", function(msg)
  105.             setState("boxStop")
  106.         end )
  107.         
  108.         
  109.         onMsg("testCancel", function(msg)
  110.             if testCancel() or (not this.getParent().getCurrentActivityGain()) then
  111.                 setState("boxStop")
  112.             else
  113.                 sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
  114.             end
  115.         end )
  116.         
  117.         onMsg("end", function(msg)
  118.             
  119.             if testCancel() then
  120.                 setState("boxStop")
  121.             else
  122.                 sendMsgThis("startLoop");
  123.             end
  124.         end )
  125.             
  126.     state("boxStop")
  127.     
  128.         onEnter(function(msg)
  129.             startAnimation("boxingStart", false, -1.0);
  130.         end )
  131.         
  132.         onMsg("end", function(msg)
  133.             exitAndGoAway();
  134.         end )    
  135.             
  136.         
  137. endStateMachine()
  138.